<?php
use Buan\Config;
use Buan\UrlCommand;
use Buan\View;

$urlRoot = Config::get('ext.Scribble.urlRoot');
View::getGlobalView()->addStylesheets("{$urlRoot}/css/scribble/auth/user.edit.css");
View::getGlobalView()->addJavascripts("{$urlRoot}/js/scribble/auth/user.edit.js");
?>

<div class="head">
	<h1>Users</h1>
	<h2><?php $this->html->e($user->isInDatabase() ? "Edit {$user->displayname}" : "Create a user"); ?></h2>
</div>

<form method="post" action="<?php $this->html->eUrl(UrlCommand::createUrl('scribble', 'auth', 'user', $user->isInDatabase() ? $user->id : 'create')); ?>">
	<div class="std std-2col">
		<div class="col-left">
			<dl class="required">
				<dt>Email: *</dt>
				<dd><input type="text" name="email" value="<?php $this->html->e($user->email); ?>" /></dd>
			</dl>
	
			<dl class="required">
				<dt>Password: *</dt>
				<dd><input type="text" name="password" value="" /></dd>
			</dl>
	
			<dl class="required">
				<dt>Display name: *</dt>
				<dt class="aid">Other users will know this user by this name</dt>
				<dd><input type="text" name="displayname" value="<?php $this->html->e($user->displayname); ?>" /></dd>
			</dl>
		</div>

		<div class="col-right">
			<dl>
				<dt>Select roles for this user</dt>
				<dd id="user-roles">
					<?php foreach($roles as $r): ?>
						<label><input type="checkbox" name="role[]" value="<?php $this->html->e($r->id); ?>" <?php echo isset($userRoles[$r->id]) ? 'checked="checked"' : ''; ?> /><?php $this->html->e($r->title); ?></label>
						<p><?php $this->html->e($r->description); ?></p>
					<?php endforeach; ?>
				</dd>
			</dl>
		</div>
	</div>
	<p>
		<button class="submit" type="submit" value="Save">Save</button>
		<?php if($user->isInDatabase()): ?>
			<button class="delete" type="submit" name="method" value="delete" rel="user-delete" disabled="disabled">Delete</button>
		<?php endif; ?>
	</p>
</form>